package com.atguigu.crowd.handler;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.atguigu.crowd.entity.vo.AddressVO;
import com.atguigu.crowd.entity.vo.DetailProjectVO;
import com.atguigu.crowd.entity.vo.OrderProjectVO;
import com.atguigu.crowd.entity.vo.OrderVO;
import com.atguigu.crowd.mapper.AddressPOMapper;
import com.atguigu.crowd.service.api.OrderService;
import com.atguigu.crowd.util.ResultEntity;

@RestController
public class OrderProviderHandler {
	
	@Autowired
	private OrderService orderService;
	
	//删除订单
	@RequestMapping("/del/order/detail/remote")
	ResultEntity<String> delOrderDetailRemote(@RequestParam("orderId") Integer orderId){
		try {
			orderService.delOrderDetail(orderId);
			
			return ResultEntity.successWithoutData();
			
		} catch (Exception e) {
			e.printStackTrace();
			
			return ResultEntity.failed(e.getMessage());
		}
	}
	
	
	//查看订单详情
	@RequestMapping("/show/order/detail/remote")
	ResultEntity<OrderProjectVO> showOrderDetailRemote(@RequestParam("orderId") Integer orderId){
		
		try {
			OrderProjectVO orderDetail = orderService.showOrderDetail(orderId);
			
			return ResultEntity.successWithData(orderDetail);
			
		} catch (Exception e) {
			e.printStackTrace();
			
			return ResultEntity.failed(e.getMessage());
		}
	}
	
	//查询我的订单项目
	@RequestMapping("/get/order/project/remote")
	ResultEntity<List<OrderProjectVO>> getOrderProjectRemote(@RequestParam("memberId") Integer memberId){
		try {
			List<OrderProjectVO> orderProjectList = orderService.getOrderProject(memberId);
			
			return ResultEntity.successWithData(orderProjectList);
			
		} catch (Exception e) {
			e.printStackTrace();
			
			return ResultEntity.failed(e.getMessage());
		}
	}
	
	//根据汇报id查询订单项目
	@RequestMapping("/get/order/project/vo/remote")
	public ResultEntity<OrderProjectVO> getOrderProjectVORemote(@RequestParam("returnId") Integer returnId){
		try {
			OrderProjectVO orderProjectVO = orderService.getOrderProjectVO(returnId);
			System.out.println(orderProjectVO);
			return ResultEntity.successWithData(orderProjectVO);
		} catch (Exception e) {
			e.getStackTrace();
			return ResultEntity.failed(e.getMessage());
		}
	}
	
	@RequestMapping("/get/address/vo/remote")
	ResultEntity<List<AddressVO>> getAddressVORemote(@RequestParam("memberId") Integer memberId){
		try {
			List<AddressVO> addressVOList = orderService.getAddressVOList(memberId);
			return ResultEntity.successWithData(addressVOList);
		} catch (Exception e) {
			e.printStackTrace();
			return ResultEntity.failed(e.getMessage());
		}
	}
	
	@RequestMapping("/save/address/vo/remote")
	ResultEntity<String> saveAddressVORemote(@RequestBody AddressVO addressVO){
		try {
			orderService.saveAddressVO(addressVO);
			return ResultEntity.successWithoutData();
		} catch (Exception e) {
			e.printStackTrace();
			return ResultEntity.failed(e.getMessage());
		}
	}

	@RequestMapping("/save/order/vo/remote")
	ResultEntity<String> saveOrderVORemote(
			@RequestBody OrderVO orderVO,
			@RequestParam("memberId") Integer memberId){
		try {
			orderService.saveOrderVO(orderVO,memberId);
			return ResultEntity.successWithoutData();
		} catch (Exception e) {
			e.printStackTrace();
			return ResultEntity.failed(e.getMessage());
		}
	}
}
